﻿// Copyright (C) 2012 Kim Jensen, TaskJunction.com
// Licensed under the MIT license: http://www.opensource.org/licenses/mit-license.php
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using TaskJunctionLib.Model;

namespace TaskJunctionLib.Mapping.JSON
{
    public class ProjectMemberMapper : JSONMapper<ProjectMember>
    {
        public override void deserializeFromJSON(System.Json.JsonValue jsonObject, ProjectMember obj)
        {
            obj.Id = jsonObject["id"].ReadAs<Int32>();
            obj.IsAdmin = jsonObject["admin"].ReadAs<string>() == "1";
            obj.ProjectId = jsonObject["project_id"].ReadAs<int>();
            obj.UserId = jsonObject["user_id"].ReadAs<int>();
            User user = new User();
            new UserMapper().deserializeFromJSON(jsonObject["user"], user);
            obj.User = user;
        }

        public override void serializeToJSON(System.Json.JsonValue jsonObject, ProjectMember obj)
        {
            jsonObject["id"] = obj.Id;
            jsonObject["admin"] = obj.IsAdmin;
            jsonObject["project_id"] = obj.ProjectId;
            jsonObject["user_id"] = obj.UserId;
            jsonObject["user"] = new UserMapper().serialize(obj.User);
        }

        protected override string JSONName()
        {
            return "project_member";
        }
    }
}
